package com.dubbo.ssmcaseconsumeboot;/**
 * @author: Zhu.QF
 * @Date: 2020/3/9 17:47
 */

import com.alibaba.dubbo.config.annotation.Reference;
import fv.pojo.Test;
import fv.service.TestService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: ssmcaseconsumeboot
 *
 * @description:
 *
 * @author: Zhuqf
 *
 * @Date: 2020/3/9 17:47 
 */
//@RestController// rest接口(json格式)是解析不到html
@Controller
@RequestMapping(value = "/api")
public class TestContorller {
    @Resource
    @Reference
    private TestService testService;



    @GetMapping("/test/{id}")
    @ResponseBody
    public  Test getTestById(@PathVariable int id)
    {
        return  testService.getTestById(id);
    }

    @GetMapping(value = "/test/all")
    @ResponseBody
    public List<Test> getAllTest()
    {
        return  testService.getAllTest();
    }

    @RequestMapping(value = "/test/add")
    public boolean addTest(Test test)
    {
        return  testService.addTest(test);
    }

    @RequestMapping(value = "/test/update")
    //@RequestMapping(value = "/test")
    public boolean updateTest(Test test)
    {
        return  testService.updateTest(test);
    }

    //@RequestMapping(value = "/api/test",method = RequestMethod.DELETE)
    @RequestMapping(value = "/test/delete/{id}")
    public boolean deleteTest(@PathVariable("id") int id)
    {
        return  testService.deleteTest(id);
    }

   /* @GetMapping(value = "/test/list")
    public String getAllTest(Model model)
    {
        List<Test> testList=testService.getAllTest();
        //model.addAttribute("tests",testList);
        return  "api/test/list12";
    }*/

    //@GetMapping(value = "/test/list")
   /* public String list(Model model)
    {
        List<Test> testList=testService.getAllTest();
        model.addAttribute("tests",testList);
        return  "/api/test/list";
    }*/

    @GetMapping(value = "/test/list")
    public String getTestList(Model model)
    {
        List<Test> testList=testService.getAllTest();
        model.addAttribute("tests",testList);
        return "testList";
    }
}

